<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Loading 加载 | MyWeb 4.x</title>
    <meta name="generator" content="VuePress 1.5.0">
    <link rel="icon" href="/my/favicon.ico">
    <script>
      var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?c4e5f73318b5cb0c389e3d9a05f831cc";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
    <meta name="description" content="基于Vue + ElementUI 的web项目工程框架，专注于公检法行业中台系统快速搭建，框架已在多个项目实战检验。">
    <link rel="preload" href="/my/assets/css/0.styles.d7ae9199.css" as="style"><link rel="preload" href="/my/assets/js/app.2b2365a7.js" as="script"><link rel="preload" href="/my/assets/js/535.c100cd07.js" as="script"><link rel="preload" href="/my/assets/js/1282.1d5157f8.js" as="script"><link rel="preload" href="/my/assets/js/1025.8afc0690.js" as="script">
    <link rel="stylesheet" href="/my/assets/css/0.styles.d7ae9199.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/my/" class="home-link router-link-active"><img src="/my/img/logo.png" alt="MyWeb 4.x" class="logo"> <span class="site-name can-hide">MyWeb 4.x</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/my/guide/" class="nav-link">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/my/guide/" class="nav-link">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Basic</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Form</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Data</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Notice</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/my/element/alert.html" class="sidebar-link">Alert 警告</a></li><li><a href="/my/element/loading.html" aria-current="page" class="active sidebar-link">Loading 加载</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/element/loading.html#区域加载" class="sidebar-link">区域加载</a></li><li class="sidebar-sub-header"><a href="/my/element/loading.html#自定义" class="sidebar-link">自定义</a></li><li class="sidebar-sub-header"><a href="/my/element/loading.html#整页加载" class="sidebar-link">整页加载</a></li><li class="sidebar-sub-header"><a href="/my/element/loading.html#服务" class="sidebar-link">服务</a></li><li class="sidebar-sub-header"><a href="/my/element/loading.html#options" class="sidebar-link">Options</a></li></ul></li><li><a href="/my/element/message.html" class="sidebar-link">Message 消息提示</a></li><li><a href="/my/element/message-box.html" class="sidebar-link">MessageBox 弹框</a></li><li><a href="/my/element/notification.html" class="sidebar-link">Notification 通知</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Navigation</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Others</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="loading-加载"><a href="#loading-加载" class="header-anchor">#</a> Loading 加载</h1> <p>加载数据时显示动效。</p> <h2 id="区域加载"><a href="#区域加载" class="header-anchor">#</a> 区域加载</h2> <p>在表格等容器中加载数据时显示。</p> <!----><h2 id="自定义"><a href="#自定义" class="header-anchor">#</a> 自定义</h2> <p>可自定义加载文案、图标和背景色。</p> <!----><h2 id="整页加载"><a href="#整页加载" class="header-anchor">#</a> 整页加载</h2> <p>页面数据加载时显示。</p> <!----><h2 id="服务"><a href="#服务" class="header-anchor">#</a> 服务</h2> <p>Loading 还可以以服务的方式调用。引入 Loading 服务：</p> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> Loading <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'element-ui'</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>在需要调用时：</p> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code>Loading<span class="token punctuation">.</span><span class="token function">service</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>其中 <code>options</code> 参数为 Loading 的配置项，具体见下表。<code>LoadingService</code> 会返回一个 Loading 实例，可通过调用该实例的 <code>close</code> 方法来关闭它：</p> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">let</span> loadingInstance <span class="token operator">=</span> Loading<span class="token punctuation">.</span><span class="token function">service</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$nextTick</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span> <span class="token comment">// 以服务的方式调用的 Loading 需要异步关闭</span>
  loadingInstance<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>需要注意的是，以服务的方式调用的全屏 Loading 是单例的：若在前一个全屏 Loading 关闭前再次调用全屏 Loading，并不会创建一个新的 Loading 实例，而是返回现有全屏 Loading 的实例：</p> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">let</span> loadingInstance1 <span class="token operator">=</span> Loading<span class="token punctuation">.</span><span class="token function">service</span><span class="token punctuation">(</span><span class="token punctuation">{</span> fullscreen<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">let</span> loadingInstance2 <span class="token operator">=</span> Loading<span class="token punctuation">.</span><span class="token function">service</span><span class="token punctuation">(</span><span class="token punctuation">{</span> fullscreen<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>loadingInstance1 <span class="token operator">===</span> loadingInstance2<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>此时调用它们中任意一个的 <code>close</code> 方法都能关闭这个全屏 Loading。</p> <p>如果完整引入了 Element，那么 Vue.prototype 上会有一个全局方法 <code>$loading</code>，它的调用方式为：<code>this.$loading(options)</code>，同样会返回一个 Loading 实例。</p> <h2 id="options"><a href="#options" class="header-anchor">#</a> Options</h2> <table><thead><tr><th>参数</th> <th>说明</th> <th>类型</th> <th>可选值</th> <th>默认值</th></tr></thead> <tbody><tr><td>target</td> <td>Loading 需要覆盖的 DOM 节点。可传入一个 DOM 对象或字符串；若传入字符串，则会将其作为参数传入 <code>document.querySelector</code>以获取到对应 DOM 节点</td> <td>object/string</td> <td>—</td> <td>document.body</td></tr> <tr><td>body</td> <td>同 <code>v-loading</code> 指令中的 <code>body</code> 修饰符</td> <td>boolean</td> <td>—</td> <td>false</td></tr> <tr><td>fullscreen</td> <td>同 <code>v-loading</code> 指令中的 <code>fullscreen</code> 修饰符</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>lock</td> <td>同 <code>v-loading</code> 指令中的 <code>lock</code> 修饰符</td> <td>boolean</td> <td>—</td> <td>false</td></tr> <tr><td>text</td> <td>显示在加载图标下方的加载文案</td> <td>string</td> <td>—</td> <td>—</td></tr> <tr><td>spinner</td> <td>自定义加载图标类名</td> <td>string</td> <td>—</td> <td>—</td></tr> <tr><td>background</td> <td>遮罩背景色</td> <td>string</td> <td>—</td> <td>—</td></tr> <tr><td>customClass</td> <td>Loading 的自定义类名</td> <td>string</td> <td>—</td> <td>—</td></tr></tbody></table></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/my/element/alert.html" class="prev">
        Alert 警告
      </a></span> <span class="next"><a href="/my/element/message.html">
        Message 消息提示
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/my/assets/js/app.2b2365a7.js" defer></script><script src="/my/assets/js/535.c100cd07.js" defer></script><script src="/my/assets/js/1282.1d5157f8.js" defer></script><script src="/my/assets/js/1025.8afc0690.js" defer></script>
  </body>
</html>
